using Admin2025.Domain.Entities.App;
using Microsoft.EntityFrameworkCore;

namespace Admin2025.Infrastructure.Data;
// 数据库上下文
public class Admin2025DbContext : DbContext
{
    public Admin2025DbContext(DbContextOptions<Admin2025DbContext> options)
        : base(options)
    {
    }
    public DbSet<AppUser> AppUsers { get; set; }
    public DbSet<AppRole> AppRoles { get; set; }
    public DbSet<AppPermission> AppPermissions { get; set; }
    public DbSet<AppResource> AppResources { get; set; }
    public DbSet<AppContent> AppContents { get; set; }

     protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // 配置多对多关系
        modelBuilder.Entity<AppUser>()
            .HasMany(u => u.Roles)
            .WithMany(r => r.Users)
            .UsingEntity(j => j.ToTable("UserRoles"));
    }
}
